
package com.xzit.tmms.controller.unit;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.xzit.tmms.bean.unit.Class;
import com.xzit.tmms.bean.unit.Unit;
import com.xzit.tmms.common.base.BaseController;
import com.xzit.tmms.common.exception.ServiceException;
import com.xzit.tmms.common.page.Page;
import com.xzit.tmms.service.unit.UnitService;
/**
 * 
 * @ClassName: UnitController
 * @Description: TODO
 * @author ChongQin
 * @date 2016年7月2日 上午10:04:56
 */
@Controller
@RequestMapping("/unit")
public class UnitController extends BaseController {
     @Resource
     private UnitService unitService;
     
     @RequestMapping("")
     public String index(){
    	 return "class/class-index";
     }
     @RequestMapping("unitIndex")
     public String unitIndex(){
    	 return "unit/unit-index";
     }
     @RequestMapping("/addClass")
     public String addClass(){
    	 return "class/class-add";
     }
	
     @RequestMapping("/addClassSubmit")
     public String addClassSubmit(Class clazz) throws ServiceException{
    	 unitService.addClass(clazz);
    	 return "redirect:/unit.action";
     }
     /**
      * 
      * @Title: queryClass
      * @Description: TODO
      * @param @param model
      * @param @return
      * @param @throws ServiceException   
      * @return String 
      * @throws
      */
     @RequestMapping("/queryClass")
 	public String queryClass(Model model) throws ServiceException {
 		Page<Map<String, Object>> page = new Page<>(getPageIndex(), getPageSize());
 		model.addAttribute("page", unitService.queryClass(page));
 		System.out.println(page.getBeanList().size());
 		return "class/class-query";
 	}
 	/**
 	 * 
 	 * @Title: deleteClass
 	 * @Description: TODO
 	 * @param @param classId
 	 * @param @return
 	 * @param @throws ServiceException   
 	 * @return String 
 	 * @throws
 	 */
 	@RequestMapping("/deleteClass")
 	public String deleteClass(Integer classId) throws ServiceException{
 		unitService.deleteClass(classId);
 		return "redirect:/unit/queryClass.action";
 	}
 	/**
 	 * 
 	 * @Title: updateClass
 	 * @Description: TODO
 	 * @param @param model
 	 * @param @param classId
 	 * @param @return
 	 * @param @throws ServiceException   
 	 * @return String 
 	 * @throws
 	 */
 	@RequestMapping("/updateClass")
 	public String updateClass(Model model,Integer classId) throws ServiceException{
 		Class clazz=unitService.getClassById(classId);
 		System.out.println(classId);
 		model.addAttribute("clazz",clazz);
 		return "class/class-update";
 	}
 	/**
 	 * 
 	 * @Title: updateClassSubmit
 	 * @Description: TODO
 	 * @param @param model
 	 * @param @param clazz
 	 * @param @return
 	 * @param @throws ServiceException   
 	 * @return String 
 	 * @throws
 	 */
 	@RequestMapping("/updateClassSubmit")
 	public String updateClassSubmit(Model model,Class clazz) throws ServiceException{
 		unitService.updateClass(clazz);
 		 return "redirect:/unit.action";
 	}
 	/**
 	 * 
 	 * @Title: queryUnit
 	 * @Description: TODO
 	 * @param @param model
 	 * @param @return
 	 * @param @throws ServiceException   
 	 * @return String 
 	 * @throws
 	 */
 	  @RequestMapping("/queryUnit")
 	 	public String queryUnit(Model model) throws ServiceException {
 	 		Page<Map<String, Object>> page = new Page<>(getPageIndex(), getPageSize());
 	 		model.addAttribute("page", unitService.queryUnit(page));
 	 		return "unit/unit-query";
 	 	}
 	  /**
 	   * 
 	   * @Title: addUnit
 	   * @Description: TODO
 	   * @param @return   
 	   * @return String 
 	   * @throws
 	   */
 	 @RequestMapping("/addUnit")
     public String addUnit(){
    	 return "unit/unit-add";
     }
	/**
	 * 
	 * @Title: addUnitSubmit
	 * @Description: TODO
	 * @param @param unit
	 * @param @return
	 * @param @throws ServiceException   
	 * @return String 
	 * @throws
	 */
     @RequestMapping("/addUnitSubmit")
     public String addUnitSubmit(Unit unit) throws ServiceException{
    	 unitService.addUnit(unit);
    	 return "unit/unit-index";
     }
     /**
      * 
      * @Title: deleteUnit
      * @Description: TODO
      * @param @param unitId
      * @param @return
      * @param @throws ServiceException   
      * @return String 
      * @throws
      */
     @RequestMapping("/deleteUnit")
  	public String deleteUnit(Integer unitId) throws ServiceException{
  		unitService.deleteUnit(unitId);
  		return "redirect:/unit/queryUnit.action";
  	}
     /**
      * 
      * @Title: updateUnit
      * @Description: TODO
      * @param @param model
      * @param @param unitId
      * @param @return
      * @param @throws ServiceException   
      * @return String 
      * @throws
      */
     @RequestMapping("/updateUnit")
  	public String updateUnit(Model model,Integer unitId) throws ServiceException{
  		Unit unit=unitService.getUnitById(unitId);
  		model.addAttribute("unit",unit);
  		return "unit/unit-update";
  	}
  	/**
  	 * 
  	 * @Title: updateUnitSubmit
  	 * @Description: TODO
  	 * @param @param model
  	 * @param @param unit
  	 * @param @return
  	 * @param @throws ServiceException   
  	 * @return String 
  	 * @throws
  	 */
  	@RequestMapping("/updateUnitSubmit")
  	public String updateUnitSubmit(Model model,Unit unit) throws ServiceException{
  		unitService.updateUnit(unit);
  		 return "unit/unit-index";
  	}
}
